import { reqUserInfo , reqLogout} from "@/api/Register"
import {deleteToken} from '@/utils/auth'
import router from "@/router"
// 服务员
const actions = {
    //获取用户信息
    async getUserInfo({commit}){
        const result = await reqUserInfo()
        if(result.code === 200){
            commit('SAVE_USER_INFO',result.data)
        }else{
            alert(result.message)
        }
    },
    //退出登录
    async logout({commit}){
        const result = await reqLogout()
        if(result.code === 200){
            commit('CLEAR_USER_INFO')
            deleteToken()
            router.push('/login')
        }
    }
}

// 厨师
const mutations = {
    SAVE_USER_INFO(state,value){
        state.info = value
    },
    CLEAR_USER_INFO(state){
        state.info = {}
    }
}

// 原材料
const state = {
    info:{}
}

const getters = {}

// 暴露
export default {
    actions,
    mutations,
    state,
    getters,
}
